<script type="text/javascript">
$(function(){
	var pg = App.base.dirEdit.ui;
	var frm = {
		code: pg.seek('code'),
		name: pg.seek('name'),
		memo: pg.seek('memo')
	}
	function getValues(){
		return {
			id: pg.params.key,
			parentId: pg.params.parent,
			code: frm.code.val(),
			name: frm.name.val(),
			memo: frm.memo.val()
		};
	}
	function setValues(o){
		pg.seek('title').html(o.key? '编辑目录':'添加目录');
		frm.code.val(o.code);
		frm.name.val(o.name);
		frm.memo.val(o.memo);
	}
	function validate(p){
		var x = App.validate, v = App.base.validation,
		msg=pg.seek('msg').html('');
		return x(v.dir.code, p.code, msg, '英文名') && x(v.dir.name, p.name, msg, '中文名');
	}
	
	pg.find('input').blur(function() {
		var pms = getValues();
		if (!validate(pms))
			return;
	});
	
	pg.seek('ok').click(function(){
		var pms = getValues();
		if(!validate(pms)) {
			return;
		}
		$.post(App.ctx + '/dir/save.do', pms, function(rs){
			var ro = mac.eval(rs);
			if (ro.success) {
				pg.callback(ro.data);//更新树	
				if(pg.close){
					pg.close();
				}else{
					//pg.callback(null, pg.params.id || pg.params.parent);
				}
			} else {
				pg.seek('msg').html(mac.msg(ro.data, ro.params));
			}
		});
		return false;
	});
	//暂时不允许改CODE
	if (pg.params.code) {
		pg.find('.msg').html('');
		frm.code.attr('disabled', 1);
	}
	setValues(pg.params);
});
</script>
<div class="title" name="title">
	编辑目录
</div>
<div class="form">
	<div class="item">
		<span class="label">英文名</span> <input type="text" name="code" /> <span
			class="msg">*</span>
		<div class="clear"></div>
	</div>
	<div class="item">
		<span class="label">中文名</span> <input type="text" name="name" /> <span
			class="msg">*</span>
		<div class="clear"></div>
	</div>
	<div class="item">
		<span class="label">描述</span>
		<textarea name="memo"></textarea>
	</div>
	<div class="item">
		<span class="label">&nbsp;</span>
		<div name="msg" class="msg"></div>
		<div class="clear"></div>
	</div>
	<div class="bottom">
		<button name="ok">保存</button>
	</div>
</div>